var app = getApp();
// pages/mine/mine.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    isAuthorize:false
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this
    that.setData({userInfo: app.globalData.userInfo });
    if (app.globalData.userInfo){
      that.setData({ 
        userInfo: app.globalData.userInfo ,
        isAuthorize: true
      });
    }else{
      wx.getUserInfo({
        success: res => {
          app.globalData.userInfo = res.userInfo;
          that.setData({ userInfo: res.userInfo });
          that.setData({
            isAuthorize: true
          })
        },
        fail: res => {
          isAuthorize: false
        }
      })
    }
  },

  menu1: function(){
    var that = this;
    wx.navigateTo({
      url: 'mine-evpi/mine-evpi?openOId=' + app.globalData.userData.openOId + '&uid=' + that.data.userData.uid + '&rank_img=' + that.data.userData.rank_img + '&is_bee=' + that.data.userData.is_bee + '&rank=' + that.data.userData.rank
    })
  },

  menu2: function () {
    wx.navigateTo({
      url: 'become/become?openOId=' + app.globalData.userData.openOId
    })
  },


  menu3: function () {
    wx.navigateTo({
      url: 'seniority/seniority?openOId=' + app.globalData.userData.openOId
    })
  },

  menu4: function () {
    wx.navigateTo({
      url: 'joined/joined?openOId=' + app.globalData.userData.openOId
    })
  },

  menu5: function () {
    wx.navigateTo({
      url: 'set/set'
    })
  },
  
  menu6: function () {
    wx.navigateTo({
      url: 'collection/collection?openOId=' + app.globalData.userData.openOId
    })
  },

  menu7: function () {
    wx.navigateTo({
      url: 'enterprisePortal/enterprisePortal?openOId=' + app.globalData.userData.openOId
    })
  },

  menu8: function () {
    wx.navigateTo({
      url: 'contact/contact?openOId=' + app.globalData.userData.openOId
    })
  },

  menu9: function () {
    wx.navigateTo({
      url: 'templet/templet?openOId=' + app.globalData.userData.openOId
    })
  },
  
  
  detail:function(){
    var that = this;
    wx.navigateTo({
      url: './money/detail/detail?openOId=' + app.globalData.userData.openOId + '&yue=' + that.data.userData.money
    })
  },
  
  getMoney: function () {
    var that = this;
    wx.navigateTo({
      url: './money/money/money?openOId=' + app.globalData.userData.openOId + '&yue=' + that.data.userData.money + '&is_bee=' + that.data.userData.is_bee
    })+ '&is_bee=' + that.data.userData.is_bee
  },

  onShow: function () {
    var that = this

    wx.showLoading({
      title: '加载中...',
    });

    wx.request({
      url: app.globalData.phpUrl + 'user/api',
      method: 'POST',
      data: { api_name: 'info', openid: app.globalData.userData.openOId },
      success: function (d) {
        that.setData({ userData: d.data.data });
        wx.hideLoading()
      }
    })
  },

  authorize: function (event){
    var that = this;
    if (event.detail.rawData) {
      app.globalData.userInfo = JSON.parse(event.detail.rawData);
      wx.request({
        url: app.globalData.phpUrl + 'index/getUnionId',
        method: "POST",
        header: { 'content-type': 'application/x-www-form-urlencoded' },
        data: { openid: app.globalData.userData.openOId, encrypteddata: event.detail.encryptedData, iv: event.detail.iv },
        success: function (e) {
        }
      })
      that.setData({
        userInfo: app.globalData.userInfo,
        isAuthorize: true
      });
    }else{
      that.setData({
        isAuthorize: false
      });
    }
  }
})